package com.fenghongzhang.day012;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class MyReceiver6 extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
       //发送一个通知
        Notification.Builder builder = new Notification.Builder(context);
        builder.setAutoCancel(true);
        builder.setSmallIcon(R.mipmap.ic_launcher);
        builder.setContentText("标题");
        builder.setContentText("内容");

        //可弹出
        builder.setPriority(Notification.PRIORITY_MAX);
        builder.setDefaults(Notification.DEFAULT_ALL);

        //可跳转
        Intent intent1 = new Intent(context,Main2Activity.class);

        PendingIntent activity = PendingIntent.getActivity(context, 0, intent1, PendingIntent.FLAG_CANCEL_CURRENT);
        builder.setContentIntent(activity);

        Notification build = builder.build();
        NotificationManager manager =(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(1,build);
    }
}
